<#include  "/common/csharp.ftl">
<#list doc.entitymodel.entity as entity>
<#if entity.@entity_name=object()>
using System;
using Spring.Data.NHibernate.Support;
using Spring.Data.NHibernate;
using NHibernate; 
using NHibernate.Criterion;
using System.Collections.Generic;
using System.Collections;
namespace pos.entity
{
    /// <summary>
    /// Summary description for ${entity.@description} 数据库访问类
    /// </summary>
    public partial  class ${entity.@entity_name?cap_first}Dao:Dao<${entity.@entity_name?cap_first}>
    {
    	
        <#if entity.prim_key.@generator="assigned" && entity.@seqID?exists>
        public static long SEQID=${entity.@seqID};
        </#if>
<#list entity.field as field>
<#if (field.@unique?if_exists?size>0) && (field.@unique="yes") >
		 public ${entity.@entity_name?cap_first} GetBy${field.@name?cap_first}(<@fieldToCSharpType field=field/> val)
		 {
		 	dc=DC.Add(Restrictions.Eq("${field.@name}",val));
		 	return (${entity.@entity_name?cap_first})dao.Execute(__GetByDcDelegate);
		 }
</#if>
</#list>

        <#if entity.prim_key.@generator="assigned" && entity.@seqID?exists>
        protected override Object __AddDelegate(ISession session)
        {
	            Sequence seq = session.Get(typeof(Sequence), SEQID) as Sequence;
            if (seq == null)
                throw new pos.excption.DesignException("Sequence 不存在");
            ${entity.@entity_name?cap_first} entity = obj as ${entity.@entity_name?cap_first};
            entity.${entity.prim_key.@field}=seq.sequenceNo++;
           Object rs= session.Save(obj);
           session.Update(seq);
		   return rs;
        }    
        </#if>
    }
}

<#break/>
</#if>
</#list>